<template>
  <div class="container">

    <div class="log-box">
      <div style="width: 100%; height: 100px; font-size: 30px; line-height: 100px; text-align: center; color: #666">欢迎登录</div>
      <div style="margin-top: 25px; text-align: center; height: 320px;">
        <el-form :model="admin">
          <el-form-item>
            <el-input v-model="admin.username" prefix-icon="el-icon-user" style="width: 80%" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input show-password v-model="admin.password" prefix-icon="el-icon-lock" style="width: 80%" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button style="width: 80%; margin-top: 10px" type="primary" @click="login()">登录</el-button>
            <div style="text-align: right;margin-right: 30px;margin-top: 10px">
              未有账号？<a href="javascript:void(0)" style="text-decoration: none" @click="navRegister">点击注册</a>
            </div>
          </el-form-item>
        </el-form>

      </div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "LoginView",
  data() {
    return {
        admin: {}
    }
  },
  created() {

  },
  methods: {
    login() {
      request.post("/admin/login", this.admin).then(res => {
        if (res.code === '200') {
          this.$message({
            message: '登录成功',
            type: 'success'
          });
          localStorage.setItem("user", JSON.stringify(res.data))
          this.$router.push("/");
        } else {
          this.$message({
            message: res.msg,
            type: 'error'
          });
        }
      })
    },
    navRegister() {
      this.$router.push("/register")
    }
  }
}
</script>

<style scoped>
.container {
  height: 100vh;
  overflow: hidden;
  background-image: url("~@/assets/bg.jpg");
  background-size: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
}
.log-box{
  width: 350px;
  height: 350px;
  margin: 150px auto;
  background-color: white;
  box-shadow: 0 0 10px rgba(0,0,0,.1);
  background-color:rgba(255,255,255,.9);
  border-radius: 5px
}
</style>